﻿using IceDog.WebApi.AnythingApi.Utils;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.WebApi.AnythingApi.Controllers
{
    /// <summary>
    /// 代理请求
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class ProxyHttpController : ControllerBase
    {
        [HttpGet, Route("[action]")]
        public ActionResult Get(string url)
        {
            var res = WebRequest.CreateDefault(new Uri(url)).GetResponse();
            var rs =  res.GetResponseStream();
            var sr = new StreamReader(rs);
            var text = sr.ReadToEnd();
            return Content(text);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet, Route("[action]")]
        public ActionResult GetOrigin()
        {
            return Ok(WebHelper.GetOrigin());
        }
    }
}
